#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
@author:atuo.cn
'''

from tkinter import *
from tkinter.ttk import *

from dialogs.patterndialog_layout import PatternDialogLayout


class PatternDialog(PatternDialogLayout):
    
    PATTERNS=[
        r"第[0-9零○一二两三四五六七八九十百千廿卅卌壹贰叁肆伍陆柒捌玖拾佰仟万１２３４５６７８９０]{1,5}[卷章节節堂讲回集部]{1}",
        r"^[第]?[0-9零○一二两三四五六七八九十百千廿卅卌壹贰叁肆伍陆柒捌玖拾佰仟万１２３４５６７８９０]{1,5}[卷章节節堂讲回集部]?",
        r"第.{1,5}章",
        r"[0-9]{1,5}\.",
    ]
    def __init__(self, master, wmtitle):
        self.selected=None
        PatternDialogLayout.__init__(self, master, wmtitle)

    def onLoad(self):
        self.listboxPatterns.insert(END, *PatternDialog.PATTERNS)
        
    #override methods of Dialog
    def apply(self):
        selected=self.listboxPatterns.curselection()
        if selected:
            self.selected=self.listboxPatterns.get(selected[0])

    #Event Handlers
    def pattern_selected(self, event):
        self.ok()
